package com.ryan.framework.converter;

import java.util.Date;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import com.ryan.utils.DateUtil;

public class DateConverter extends StrutsTypeConverter {

	@SuppressWarnings("rawtypes")
	@Override
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
		if(null!=arg1&&!"".equals(arg1[0])){
			return DateUtil.string2Date(arg1[0],"yyyy-MM-dd HH:mm:ss");
		}else{
			return null;
		}
	}

	@SuppressWarnings("rawtypes")
	@Override
	public String convertToString(Map arg0, Object arg1) {
		if(null!=arg1){
			return DateUtil.date2String((Date)arg1, "yyyy-MM-dd HH:mm:ss");
		}else{
			return "";
		}
	}

}
